package com.fulin.dynamic;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

public class DynamicWork implements InvocationHandler{
	
	private Object work;
	
	public DynamicWork(Object work) {
		this.work = work;
	}
	

	@Override
	public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
		Object result = null;
		if("say".equals(method.getName())){
			System.out.println("before...");
			result = method.invoke(work, args);
			System.out.println("after...");
		}else{
			result = method.invoke(work, args);
		}
		return result;
	}

}
